package com.ymkj.testdemo.utils;

import org.springframework.util.StringUtils;

import java.io.IOException;
import java.util.Scanner;

public class CpuUtil {
    private static String getCpu4Windows() {
        try {
            Process process = Runtime.getRuntime().exec("wmic cpu get name");
            process.getOutputStream().close();
            Scanner sc = new Scanner(process.getInputStream());
            String key = sc.next();
            String cpuName = "";
            while (sc.hasNext()) {
                cpuName += sc.next() + " ";
            }
            return StringUtils.isEmpty(cpuName) ? null : cpuName.substring(0, cpuName.length() - 1);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return null;
    }


    public static String getCpu() {

        return getCpu4Windows();

    }


    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        System.out.println(getCpu());
        System.out.println("time:" + (System.currentTimeMillis() - start));
    }

}
